/**
 *
 */
package gemini.basic.dao.impl;

import gemini.basic.dao.GmnDao;
import gemini.basic.dao.LevelDao;
import gemini.basic.model.Level;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 *
 *
 */
public class LevelDaoImpl extends HibernateDaoSupport implements LevelDao {

	private GmnDao gmnDao;

	public void setGmnDao(GmnDao gmnDao) {
		this.gmnDao = gmnDao;
	}

	@Override
	public List<Level> getAll() {

		DetachedCriteria dtCri = DetachedCriteria.forClass(Level.class);

		List<Object> lvList = gmnDao.findByCriteria(dtCri);
		List<Level> result = null;

		if (lvList != null) {
			result = new ArrayList<Level>(lvList.size());

			for (Object ob : lvList) {
				result.add((Level) ob);
			}
		}

		return result;
	}

	@Override
	public Level getLevelById(int levelId) {
		Level result = getHibernateTemplate().get(Level.class, levelId);
		return result;
	}

	@Override
	public boolean delete(Level level) {
		getHibernateTemplate().delete(level);
		return true;
	}

	@Override
	public Level saveOrUpdate(Level level, boolean flush) {
		Level result = null;
		if (flush) {
			result = (Level) gmnDao.saveOrUpdateAndFlush(level);
		} else {
			result = (Level) gmnDao.saveOrUpdate(level);
		}
		return result;
	}
}
